<template>
  <template v-if="user">
    <van-cell title="当前用户" is-link to="/user/edit" :value="user?.userName"
              @click="toEdit('userName','昵称',user.userName)"/>
    <van-cell title="修改信息" is-link to="/user/update/"/>
    <van-cell title="我创建的队伍" is-link to="/team/my/create"/>
    <van-cell title="我加入的队伍" is-link to="/team/my/join"/>
    <van-button type="primary" @click="logout">退出账号</van-button>
  </template>
</template>
<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";
import myAxios from "../plugins/myAxios.ts";
import {showFailToast, showSuccessToast} from "vant";

const router = useRouter();
const user = ref();
onMounted(async () => {
      const res = await getCurrentUser();
      user.value = res;
    }
)
const toEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: "/user/edit",
    query: {
      editKey: editKey,
      editName: editName,
      currentValue: currentValue,
    }
  })
}
const logout =async ()=>{
  const res = await myAxios.post('/user/logout');
  if(res.code ===0){
    showSuccessToast('退出成功')
    router.push('/user/login')
  }else {
    showFailToast("退出失败")
  }
}
</script>


<style scoped>

</style>